﻿using System;
using System.Data;

namespace Login.ADL
{
    public class tb_shangkeClass
    {
        /// <summary>
        /// 所有实验班级表格提取
        /// </summary>
        /// <returns></returns>
        #region
        public static DataSet getData()
        {
            //构造安排实验的班级的sql语句
            string sql = "select ClassName,ArrangeFou from tb_Class";
            //提取安排实验的班级
            DataSet ds = Helpsql.getdata(sql);
            return ds;
        }
        #endregion

        /// <summary>
        /// 班级上课时间强制改变
        /// </summary>
        /// <param name="banJi"></param>
        #region
        public static void timeModify(string banJi)
        {
            //构造修改班级表的sql语句
            string sql = "update tb_class set ArrangeFou='' where ClassName='{0}'";
            sql = string.Format(sql,banJi);
            //修改班级表
            Helpsql.getxiu(sql);
            //搜索班级ID
            string id = getClassId(banJi);
            //更新排课表的SQL语句
            sql = "update tb_NoClass set TimeId='' where ClassId='{0}'";
            sql = string.Format(sql, id);
            //更新排课表
            Helpsql.getxiu(sql);
        }
        #endregion

        /// <summary>
        /// 班级上课时间添加
        /// </summary>
        /// <param name="banJi">班级名</param>
        /// <param name="time">上课时间</param>
        #region
        public static void timeAdd(string banJi,string time)
        {
            //构造已安排班级的sql语句
            string sql = "update tb_class set ArrangeFou='已安排' where ClassName='{0}'";
            sql = string.Format(sql, banJi);
            //已安排班级更新
            Helpsql.getxiu(sql);
            //构造搜索时间ID的sql语句
            sql = "select TimeId from tb_Time where TimeName='{0}'";
            sql = string.Format(sql, time);
            //搜索时间Id
            string timeId = Convert.ToString(Helpsql.getgeti(sql));
            //搜索班级Id
            string classId = getClassId(banJi);
            //构造更新排课表的sql语句
            sql = "update tb_NoClass set TimeId='{0}' where ClassId='{1}'";
            sql = string.Format(sql, timeId, classId);
            //更新排课表
            Helpsql.getxiu(sql);
        }
        #endregion

        /// <summary>
        /// 搜索班级的Id
        /// </summary>
        /// <param name="className">班级名称</param>
        /// <returns></returns>
        #region
        public static string getClassId(string className)
        {
            //构造搜索班级Id的sql语句
            string sql = "select ClassId from tb_Class where ClassName='{0}'";
            sql = string.Format(sql, className);
            //搜索班级Id
            return Convert.ToString(Helpsql.getgeti(sql));
        }
        #endregion

        /// <summary>
        /// 搜索班级名
        /// </summary>
        /// <param name="className">班级ID</param>
        /// <returns></returns>
        #region
        public static string getClassName(string classId)
        {
            //构造搜索班级Id的sql语句
            string sql = "select ClassName from tb_Class where ClassId='{0}'";
            sql = string.Format(sql, classId);
            //搜索班级Id
            return Convert.ToString(Helpsql.getgeti(sql));
        }
        #endregion
    }
}
